﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xKnight.Data;
using xKnight.Models;

namespace xKnight.Attacking.CSRF
{
    internal class CsrfAttacker : Attacker
    {
        public CsrfAttacker(Models.Attack attack, int numberOfThreads, Models.Host[] hosts):
            base(attack,numberOfThreads,hosts)
        {

        }
        public override void Attack()
        {
            StartAgents();
        }

        protected override AttackingSharedReource CreateAttackingSharedReource(params object[] inputs)
        {
            Form[] forms = DataLayer.GetForms(_hosts);

            HashSet<string> hashset = new HashSet<string>();
            List<Webpage> webpages=new List<Webpage>();

            for (int i = 0; i < forms.Length; i++)
            {
                if (!hashset.Contains(forms.ElementAt(i).Webpage.Url))
                {
                    hashset.Add(forms.ElementAt(i).Webpage.Url);
                    webpages.Add(forms.ElementAt(i).Webpage);
                }
            }

            object sharedLock = new object();

            return new CsrfAttackingSharedResource(webpages.ToArray(), sharedLock, _attack);
        }
    }
}
